@model EIMS.Models.Employee

@{
    ViewData["Title"] = "员工详情";
}

<div class="container-fluid px-4">
    <h1 class="mt-4">@ViewData["Title"]</h1>
    <ol class="breadcrumb mb-4">
        <li class="breadcrumb-item"><a asp-controller="Home" asp-action="Index">首页</a></li>
        <li class="breadcrumb-item"><a asp-controller="Employees" asp-action="Index">员工管理</a></li>
        <li class="breadcrumb-item active">员工详情</li>
    </ol>

    @if (TempData["SuccessMessage"] != null)
    {
        <div class="alert alert-success alert-dismissible fade show" role="alert">
            @TempData["SuccessMessage"]
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    }
    
    <div class="row">
        <div class="col-md-8">
            <div class="card mb-4">
                <div class="card-header">
                    <i class="fas fa-user me-1"></i>
                    基本信息
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-12 mb-3">
                            <div class="d-flex justify-content-between align-items-center">
                                <h4>@Model.Name</h4>
                                <div>
                                    @if (Model.Status == EIMS.Models.Enums.EmployeeStatus.Active)
                                    {
                                        <span class="badge bg-success">@Html.DisplayFor(model => model.Status)</span>
                                    }
                                    else if (Model.Status == EIMS.Models.Enums.EmployeeStatus.OnLeave)
                                    {
                                        <span class="badge bg-warning">@Html.DisplayFor(model => model.Status)</span>
                                    }
                                    else
                                    {
                                        <span class="badge bg-danger">@Html.DisplayFor(model => model.Status)</span>
                                    }
                                </div>
                            </div>
                        </div>
                    </div>

                    <dl class="row">
                        <dt class="col-sm-3">
                            @Html.DisplayNameFor(model => model.EmployeeNumber)
                        </dt>
                        <dd class="col-sm-9">
                            @Html.DisplayFor(model => model.EmployeeNumber)
                        </dd>
                        
                        <dt class="col-sm-3">
                            @Html.DisplayNameFor(model => model.Gender)
                        </dt>
                        <dd class="col-sm-9">
                            @Html.DisplayFor(model => model.Gender)
                        </dd>
                        
                        <dt class="col-sm-3">
                            @Html.DisplayNameFor(model => model.DateOfBirth)
                        </dt>
                        <dd class="col-sm-9">
                            @(Model.DateOfBirth.HasValue ? Model.DateOfBirth.Value.ToString("yyyy-MM-dd") : "-")
                        </dd>
                        
                        <dt class="col-sm-3">
                            @Html.DisplayNameFor(model => model.Department)
                        </dt>
                        <dd class="col-sm-9">
                            @(Model.Department?.Name ?? "-")
                        </dd>
                        
                        <dt class="col-sm-3">
                            @Html.DisplayNameFor(model => model.PhoneNumber)
                        </dt>
                        <dd class="col-sm-9">
                            @Html.DisplayFor(model => model.PhoneNumber)
                        </dd>
                        
                        <dt class="col-sm-3">
                            @Html.DisplayNameFor(model => model.Email)
                        </dt>
                        <dd class="col-sm-9">
                            @Html.DisplayFor(model => model.Email)
                        </dd>
                        
                        <dt class="col-sm-3">
                            @Html.DisplayNameFor(model => model.Address)
                        </dt>
                        <dd class="col-sm-9">
                            @Html.DisplayFor(model => model.Address)
                        </dd>
                        
                        <dt class="col-sm-3">
                            @Html.DisplayNameFor(model => model.HireDate)
                        </dt>
                        <dd class="col-sm-9">
                            @Model.HireDate.ToString("yyyy-MM-dd")
                        </dd>
                        
                        @if (Model.TerminationDate.HasValue)
                        {
                            <dt class="col-sm-3">
                                @Html.DisplayNameFor(model => model.TerminationDate)
                            </dt>
                            <dd class="col-sm-9">
                                @Model.TerminationDate.Value.ToString("yyyy-MM-dd")
                            </dd>
                        }
                        
                        <dt class="col-sm-3">
                            @Html.DisplayNameFor(model => model.CreatedAt)
                        </dt>
                        <dd class="col-sm-9">
                            @Model.CreatedAt.ToString("yyyy-MM-dd HH:mm:ss")
                        </dd>
                        
                        @if(Model.UpdatedAt.HasValue)
                        {
                            <dt class="col-sm-3">
                                @Html.DisplayNameFor(model => model.UpdatedAt)
                            </dt>
                            <dd class="col-sm-9">
                                @Model.UpdatedAt.Value.ToString("yyyy-MM-dd HH:mm:ss")
                            </dd>
                        }
                    </dl>
                    
                    <div class="mt-3">
                        <a asp-action="Index" class="btn btn-secondary">返回列表</a>
                        @if (User.IsInRole("Admin") || User.IsInRole("Manager"))
                        {
                            <a asp-action="Edit" asp-route-id="@Model.Id" class="btn btn-primary">
                                <i class="fas fa-edit me-1"></i> 编辑
                            </a>
                            <a asp-action="AddHistory" asp-route-id="@Model.Id" class="btn btn-success">
                                <i class="fas fa-history me-1"></i> 添加历史记录
                            </a>
                        }
                        @if (User.IsInRole("Admin"))
                        {
                            <a asp-action="Delete" asp-route-id="@Model.Id" class="btn btn-danger">
                                <i class="fas fa-trash me-1"></i> 删除
                            </a>
                        }
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card mb-4">
                <div class="card-header">
                    <i class="fas fa-info-circle me-1"></i>
                    员工信息卡
                </div>
                <div class="card-body text-center">
                    <div class="mb-3">
                        <i class="fas fa-user-circle fa-7x text-primary"></i>
                    </div>
                    <h5>@Model.Name</h5>
                    <p class="text-muted">@(Model.Department?.Name ?? "-")</p>
                    <p>
                        <span class="badge bg-primary">@Model.EmployeeNumber</span>
                        @if (Model.Status == EIMS.Models.Enums.EmployeeStatus.Active)
                        {
                            <span class="badge bg-success">@Html.DisplayFor(model => model.Status)</span>
                        }
                        else if (Model.Status == EIMS.Models.Enums.EmployeeStatus.OnLeave)
                        {
                            <span class="badge bg-warning">@Html.DisplayFor(model => model.Status)</span>
                        }
                        else
                        {
                            <span class="badge bg-danger">@Html.DisplayFor(model => model.Status)</span>
                        }
                    </p>
                    <div class="mt-3">
                        <p><i class="fas fa-envelope me-2"></i>@(Model.Email ?? "-")</p>
                        <p><i class="fas fa-phone me-2"></i>@Model.PhoneNumber</p>
                        <p><i class="fas fa-calendar me-2"></i>入职日期: @Model.HireDate.ToString("yyyy-MM-dd")</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <div class="card mb-4">
        <div class="card-header">
            <i class="fas fa-history me-1"></i>
            员工历史记录
        </div>
        <div class="card-body">
            @if (Model.EmployeeHistories != null && Model.EmployeeHistories.Any())
            {
                <table class="table table-striped table-hover">
                    <thead>
                        <tr>
                            <th>记录类型</th>
                            <th>生效日期</th>
                            <th>原部门</th>
                            <th>新部门</th>
                            <th>备注</th>
                            <th>创建时间</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var history in Model.EmployeeHistories.OrderByDescending(h => h.EffectiveDate))
                        {
                            <tr>
                                <td>@history.Type</td>
                                <td>@history.EffectiveDate.ToString("yyyy-MM-dd")</td>
                                <td>@(history.OldDepartment?.Name ?? "-")</td>
                                <td>@(history.NewDepartment?.Name ?? "-")</td>
                                <td>@history.Remarks</td>
                                <td>@history.CreatedAt.ToString("yyyy-MM-dd HH:mm")</td>
                            </tr>
                        }
                    </tbody>
                </table>
            }
            else
            {
                <p class="text-muted">暂无历史记录</p>
            }
        </div>
    </div>
</div> 